package com.hiray.demos.visualEffect

import android.app.Activity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import android.util.Log
import com.hiray.demos.R
import kotlinx.android.synthetic.main.activity_scroll_multi_select.*

class ScrollMultiSelectActivity : Activity(), ScrollMultiSelectItemTouchListener.OnItemSelectListener {

    val TAG = "ScrollMultiSelectItem"
    val multiSelectAdapter = MultiSelectAdapter()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_scroll_multi_select)
        recyclerView.adapter = multiSelectAdapter
        recyclerView.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(this, androidx.recyclerview.widget.LinearLayoutManager.VERTICAL, false)
        recyclerView.addOnItemTouchListener(ScrollMultiSelectItemTouchListener(this))
    }

    override fun onPrePare() {
        multiSelectAdapter.setMultiSelectReady()
    }

    override fun onItemVisited(position: Int) {
        Log.i(TAG, "onItemVisited: ")
        multiSelectAdapter.toggle(position)
    }

    override fun onBackPressed() {
        if (multiSelectAdapter.isMultiSelect()) {
            multiSelectAdapter.cancelMultiSelect()
        } else
            super.onBackPressed()
    }
}
